<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="type1"
          @click="handleDelivery"
          v-hasPermi="['output:outSourcing:oneClickDelivery']"
        >
          一键出库
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-circle-check"
          size="mini"
          :disabled="type1"
          @click="handlePost"
          v-hasPermi="['output:outSourcing:post']"
        >
          过账
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['output:outSourcing:export']"
        >
          导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport2(1)"
          v-hasPermi="['output:outSourcing:export']"
        >
          出货明细
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport2(2)"
          v-hasPermi="['output:outSourcing:export']"
        >
          出货统计
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#bb0331">通过</Tag>
      <Tag type="dot" size="default" color="#0323af">检验</Tag>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :data="outSourcingList"
      :height="tableH"
      :cell-style="iCellStyle"
      @row-click="clickRwm"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" type="index" width="40" align="center" />
      <el-table-column
        label="委外单号"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="wfmDjbh"
      />
      <el-table-column
        label="委外日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="wfmWfrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.wfmWfrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="领料类型"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmType"
      >
        <template #default="scope">
          <dict-tag :options="wfmTypeOptions" :value="scope.row.wfmType" />
        </template>
      </el-table-column>
      <el-table-column
        label="仓库代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.wfmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="部门名称"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmBmmc"
      />
      <el-table-column
        label="厂商代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmCsdm"
      >
        <template #default="scope">
          <dict-tag :options="allCsOptions" :value="scope.row.wfmCsdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmDesc"
      />
      <el-table-column
        label="拒收备注"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmNgdesc"
      />
      <el-table-column
        label="原因代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmYydm"
      >
        <template #default="scope">
          <dict-tag :options="reasonTypeOptions" :value="scope.row.wfmYydm" />
        </template>
      </el-table-column>
      <el-table-column
        label="原因描述"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmYyms"
      />
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="wfmJlrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.wfmJlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmShry"
      />
      <el-table-column
        label="审核日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="wfmShrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.wfmShrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="wfmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="wfmGzrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.wfmGzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
    </el-table>

    <el-tabs v-model="activeTab">
      <el-tab-pane label="领料明细" name="first">
        <el-table
          border
          stripe
          :height="tableHChild"
          :data="chdDetList"
          :cell-style="iCellStyle2"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="#" type="index" align="center" fixed="left" />
          <el-table-column
            label="销售单号"
            align="center"
            prop="wfdSodh"
            fixed="left"
          />
          <el-table-column label="领料物料代码" align="center" prop="wfdWldm" />
          <el-table-column label="规格描述" align="center" prop="itmPmgg" />
          <el-table-column
            label="客户物料代码"
            align="center"
            prop="itmCustwldm"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="存放位置"
            :show-overflow-tooltip="true"
            align="center"
            prop="wfdCwdm"
          >
            <template #default="scope">
              <dict-tag :options="allCwOptions" :value="scope.row.wfdCwdm" />
            </template>
          </el-table-column>
          <el-table-column label="最小包装" align="center" prop="wfdMinbz" />
          <el-table-column label="申请数量" align="center" prop="wfdSqsl" />
          <el-table-column label="出库数量" align="center" prop="wfdCksl" />
          <el-table-column label="出库人员" align="center" prop="wfdCkry" />
          <el-table-column label="出库日期" align="center" prop="wfdCkrq">
            <template #default="scope">
              <span>{{ parseTime(scope.row.wfdCkrq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="100"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleConfirm(scope.row)"
                :disabled="type1"
                v-hasPermi="['output:outSourcing:confirmCk']"
              >
                出库确认
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="领料统计" name="second">
        <el-table border stripe :height="tableHChild" :data="chdDetTotalList">
          <el-table-column label="#" type="index" align="center" fixed="left" />
          <el-table-column label="物料代码" align="center" prop="wfdWldm" />
          <el-table-column label="规格描述" align="center" prop="itmPmgg" />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="存放位置"
            :show-overflow-tooltip="true"
            align="center"
            prop="wfdCwdm"
          >
            <template #default="scope">
              <dict-tag :options="allCwOptions" :value="scope.row.wfdCwdm" />
            </template>
          </el-table-column>
          <el-table-column label="申请数量" align="center" prop="wfdSqsl" />
          <el-table-column label="出库数量" align="center" prop="wfdCksl" />
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="450px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="108px"
      >
        <el-col :span="24">
          <el-form-item label="委外单号" prop="wfmDjbh">
            <el-input
              v-model="queryParams.wfmDjbh"
              placeholder="请输入委外单号"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="委外日期">
            <el-date-picker
              v-model="daterangeWfmWfrq"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="状态标志">
            <el-radio-group v-model="queryParams.wfmZtbz">
              <el-radio
                v-for="dict in wfmZtbzOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
                >{{ dict.dictLabel }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 出库确认对话框   -->
    <el-dialog
      :title="title"
      v-model="resultOpen"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form
        ref="wfdForm"
        :model="wfdForm"
        label-width="88px"
        :rules="wfdFormRules"
      >
        <el-col :span="24">
          <el-form-item label="委外单号" prop="wfdDjbh">
            <el-input v-model="wfdForm.wfdDjbh" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="wfdWldm">
            <el-input v-model="wfdForm.wfdWldm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="品名规格" prop="itmPmgg">
            <el-input v-model="wfdForm.itmPmgg" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请数量" prop="wfdSqsl">
            <el-input v-model="wfdForm.wfdSqsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="存放位置" prop="wfdCwdm">
            <el-select
              v-model="wfdForm.wfdCwdm"
              placeholder="请选择入库类型"
              disabled
            >
              <el-option
                v-for="dict in allCwOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最小包装" prop="wfdMinbz">
            <el-input v-model="wfdForm.wfdMinbz" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="出库数量" prop="wfdCksl">
            <el-input
              v-model="wfdForm.wfdCksl"
              type="number"
              @input="changValue"
            />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ckSubmit">确 定</el-button>
        <el-button @click="resultOpen = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOutSourcing,
  exportOutSourcing,
  mxList,
  exportOutSourcingMx,
  oneClickDelivery,
  confirmCk,
  wfmPost,
} from "@/api/output/outSourcing";
import { getAll } from "@/api/repertory/Storage";
import { getAllCs } from "@/api/putStorage/putStorageAdd";

export default {
  name: "OutSourcingPost",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: null,
      chdDetList: [],
      chdDetTotalList: [],
      serachAddList: [],
      allCwOptions: [],
      wfmZtbzOptions: [],
      showSearched: true,
      tjType: true,
      rollbackForm: {},
      rollbackFormRules: {
        wfmNgdesc: [
          { required: true, message: "请输入撤回理由", trigger: "blur" },
        ],
      },
      tableHData: 300,
      tableH: 250,
      tableHChild: 300,
      tableHAdd: 250,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      resultOpen: false,
      activeTab: "first",
      wfmIds: null,
      kcmKykcChild: null,
      // 总条数
      total: 0,
      rowClickData: null,
      // 委外加工发料表格数据
      outSourcingList: [],
      // 弹出层标题
      title: "",
      totalChild: "",
      openChildren: false,
      // 是否显示弹出层
      open: false,
      // 委外日期时间范围
      daterangeWfmWfrq: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],
      unitFlagOptions: [],
      //领料类型
      wfmTypeOptions: [],
      //有效存储仓库
      storageOptions: [],
      //所有储存仓库
      allStorageOptions: [],
      //原因类别
      reasonTypeOptions: [],
      selectRow: [],
      allCsOptions: [],
      //
      type1: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 25,
        wfmDjbh: null,
        wfmWfrq: null,
        wfmZtbz: "2",
        wfmTjflag: "1",
      },
      // 查询子项参数
      queryChildParams: {
        pageNum: 1,
        pageSize: 25,
        //销售单号
        wfmSodh: null,
        wfmDjbh: null,
        wfdWldm: null,
        wfdCgdh: null,
        //领料类型
        wfmType: null,
        //仓库代码
        itmCkdm: null,
        itmPmgg: null,
      },
      // 表单参数
      form: {},
      wfdForm: {},
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      // 表单校验
      rules: {
        wfmWfrq: [
          { required: true, message: "委外日期不能为空", trigger: "blur" },
        ],
        wfmType: [
          { required: true, message: "领料类型不能为空", trigger: "change" },
        ],
        wfmCkdm: [
          { required: true, message: "仓库代码不能为空", trigger: "blur" },
        ],
        wfmCsdm: [
          { required: true, message: "厂商代码不能为空", trigger: "blur" },
        ],
      },
      wfdFormRules: {
        wfdCksl: [
          { required: true, message: "请输入出库数量", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    //领料类型
    this.getDicts("outsourcing_requisition_type").then((response) => {
      this.wfmTypeOptions = response.data;
    });
    this.getDicts("sys_post_ztbz").then((response) => {
      this.wfmZtbzOptions = response.data;
    });
    //原因类别
    this.getDicts("reason_category").then((response) => {
      this.reasonTypeOptions = response.data;
    });

    getAll().then((response) => {
      this.allCwOptions = response.data;

      for (let item2 of this.allCwOptions) {
        item2.dictLabel = item2.storageDefaultstorage;

        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });
    //单位
    this.getDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    //所有仓库
    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    getAllCs().then((response) => {
      this.allCsOptions = response.data;
      for (let item of this.allCsOptions) {
        item.dictLabel = item.csmCs;
        item.listClass = "default";
        item.dictValue = item.csmCsdm;
      }
    });
    this.getList();
  },
  methods: {
    /** 颜色事件 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.wfmZtbz == "1" && row.wfmTjflag == "1") {
        return "color:#0fac09";
      }
      //通过
      else if (row.wfmZtbz == "2" && row.wfmTjflag == "1") {
        return "color:#0323af";
      }
      //检验
      else if (row.wfmZtbz == "6" && row.wfmTjflag == "1") {
        return "color:#bb0331";
      }
    },
    iCellStyle2: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.wfdCkry) {
        return "color:#bb0331";
      }
    },
    /** 查询委外加工发料列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeWfmWfrq && "" != this.daterangeWfmWfrq) {
        this.queryParams.params["beginWfmWfrq"] = this.moment(
          this.daterangeWfmWfrq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endWfmWfrq"] = this.moment(
          this.daterangeWfmWfrq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.pageNum = 1;
      listOutSourcing(this.queryParams).then((response) => {
        this.outSourcingList = [];
        this.chdDetList = [];
        this.chdDetTotalList = [];
        this.outSourcingList = this.outSourcingList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRwm(row);
        } else if (
          this.outSourcingList != null &&
          this.outSourcingList.length > 0
        ) {
          this.clickRwm(this.outSourcingList[0]);
        }
      });
    },

    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 25;
        this.queryParams.pageNum++;
        listOutSourcing(this.queryParams).then((response) => {
          this.outSourcingList = this.outSourcingList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.openChildren = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wfmId: null,
        wfmDjbh: null,
        wfmWfrq: new Date(),
        wfmType: null,
        wfmCkdm: null,
        wfmBmmc: null,
        wfmDesc: null,
        wfmTjflag: null,
        wfmNgdesc: null,
        wfmZtbz: null,
        wfmJlry: null,
        wfmJlrq: null,
        wfmShry: null,
        wfmShrq: null,
        wfmGzry: null,
        wfmGzrq: null,
        wfmYydm: null,
        wfmYyms: null,
        wfmCsdm: null,
      };
      this.resetForm("form");
    },

    resetWfdForm() {
      this.wfdForm = {
        wfdId: null,
        wfdDjbh: null,
        wfdWldm: null,
        itmPmgg: null,
        wfdSqsl: null,
        wfdCwdm: null,
        wfdMinbz: null,
        wfdCksl: null,
      };

      this.resetForm("wfdForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.outSourcingList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeWfmWfrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 单击头表
    clickRwm(selection) {
      if (selection != null) {
        this.type1 = !(
          selection != null &&
          selection.wfmZtbz == "2" &&
          selection.wfmTjflag == "1"
        );
        this.ids = selection.wfmId;
        this.rowClickData = selection;
        this.getRwdDetList(selection.wfmDjbh);
      }
    },
    //  明细
    getRwdDetList(data) {
      mxList(data).then((response) => {
        this.chdDetList = response.data.list1;
        this.chdDetTotalList = response.data.list2;
      });
    },
    handleSearch() {
      this.reset();
      this.title = "查询委外加工发料";
      this.openSearch = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有委外加工发料数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportOutSourcing(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport2(index) {
      this.$confirm("是否确认导出?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportOutSourcingMx(this.rowClickData.wfmDjbh, index);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    /**  一键检验 */
    handleDelivery() {
      if (this.chdDetList == null || this.chdDetList.length === 0) {
        this.msgError("该单据无明细");
      } else {
        this.$confirm("是否进行一键检验作业?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            return oneClickDelivery(this.rowClickData.wfmDjbh);
          })
          .then((response) => {
            this.msgSuccess("检验成功");
            this.getRwdDetList(this.rowClickData.wfmDjbh);
          });
      }
    },

    /** 出库确认 */
    handleConfirm(row) {
      this.resetWfdForm();
      //开始赋值
      this.wfdForm.wfdDjbh = row.wfdDjbh;
      this.wfdForm.wfdId = row.wfdId;
      this.wfdForm.wfdWldm = row.wfdWldm;
      this.wfdForm.itmPmgg = row.itmPmgg;
      this.wfdForm.wfdSqsl = row.wfdSqsl;
      this.wfdForm.wfdCwdm = row.wfdCwdm;
      this.wfdForm.wfdMinbz = row.wfdMinbz;
      this.wfdForm.wfdCksl = row.wfdSqsl;
      this.title = "出库确认";
      this.resultOpen = true;
    },

    changValue() {
      if (
        this.wfdForm.wfdCksl &&
        (this.wfdForm.wfdCksl > this.wfdForm.wfdSqsl ||
          this.wfdForm.wfdCksl === 0)
      ) {
        this.msgError("请输入大于0,并且小于" + this.wfdForm.wfdSqsl + "的数量");

        this.wfdForm.wfdCksl = this.wfdForm.wfdSqsl;
      }
    },

    //出库确认
    ckSubmit() {
      this.$refs["wfdForm"].validate((valid) => {
        if (valid) {
          confirmCk(this.wfdForm.wfdId, this.wfdForm.wfdCksl).then(
            (response) => {
              this.resultOpen = false;
              this.getRwdDetList(this.rowClickData.wfmDjbh);
            }
          );
        }
      });
    },

    /** 过账 */
    handlePost() {
      const bln = this.chdDetList.some((i) => !i.wfdCkry || !i.wfdCkrq);
      if (bln) {
        this.msgError("存在未确认出库的材料，请先检验后再进行操作！");
        return;
      }
      const cjmIds = this.rowClickData.wfmDjbh;
      if (cjmIds) {
        this.$confirm(
          '是否确认过账委外编号为"' + cjmIds + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function () {
            return wfmPost(cjmIds);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("过账成功");
          })
          .catch(() => {});
      } else {
        this.msgError("无过账单据");
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
